<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of user_model
 *
 * @author hassanali
 */
class currentadmin_model extends admin_model {

    //put your code here
    public function __construct() {
        parent::__construct();
        $this->table = 'user';
    }

    public function login($username, $password) {

        $this->db->where_in('mode', array('admin', 'manager'));
        $sql = $this->db->get_where($this->table, array('username' => $username, 'password' => md5($password), 'trash' => 'NO'));
        if ($sql->num_rows()){
            return $row = $sql->row();
        } else {
            return false;
        }
    }

    public function update_user_login($user_id) {
        $this->db->update('user', array('last_login' => date('Y-m-d H:i:s')), array('id' => $user_id));
    }
    
    /*protected function get_data_report($data = '', $action = '') {
        $subject = lang('report_' . $action);
        $data = json_decode($data);
        if (is_object($data)) {
            $data = get_object_vars($data);
        }
        if (is_array($data)) {
            $replace_key = array();
            $replace_val = array();
            foreach ($data as $key => $value) {
                if ($key == 'statue_id') {
                    $replace_key[] = '%' . $key;
                    
                    $statues = get_statues($value, '1');
                    $replace_val[] = $statues->title;
                } else {
                    $replace_key[] = '%' . $key;
                    $replace_val[] = $value;
                }
            }
           
            return str_replace($replace_key, $replace_val, $subject);
        } else {
            return str_replace('%s', $data, $subject);
        }
    }

    public function manager_report($data) {
        $result = array();

        if (count($data) > 1) {
            foreach ($data as $key => $value) {
                $result[$key]['id'] = $value->id;
                $result[$key]['create_date'] = $value->create_date;
                $result[$key]['report'] = $this->get_report($value->action);
                $result[$key]['data'] = $this->get_data_report($value->contant, $value->action);
            }
        } else {
            $result[0]['id'] = $data->id;
            $result[0]['create_date'] = $data->create_date;
            $result[0]['report'] =lang('action_'.$data->action);
            $result[0]['data'] =$this->get_data_report($data->contant, $data->action); //json_decode($data->contant);
        }


        return $result;
    }
    
    protected function get_report($action) {
        return lang('action_' . $action);
    }*/

}
